<template>
  <div class='hot-movie'>
    <!-- 热门电影项目 -->
    <div
      class="hot-movie-item"
      v-for="(item, index) in info"
      :key="index"
    >
      <router-link :to="{ name: 'Detail', params: { id: item.id } }">
        <!-- 序号 -->
        <div class="order">
          {{ index+1 }}
        </div>
        <!-- 电影封面 -->
        <div class="pic">
          <van-image :src="item.images.small" fit="contain" />
        </div>
        <!-- 电影详情 -->
        <div class="info-content">
          <!-- 标题 -->
          <div class="info">
            <div class="info-title">
              <h3>{{ item.title }}({{ item.year }})</h3>
            </div>
            <!-- 评分 -->
            <div class="rate">
              <van-rate
                :value="(item.rating.average / 10) * 5"
                :size="10"
                color="#ff9a03"
                void-icon="star"
                void-color="#eee"
              />
              <span style="margin-left: 10px">{{ item.rating.average }}</span>
            </div>
            <!-- 标签 -->
            <div class="tags">
              <van-tag plain type="primary">
                {{ item.subtype === 'movie' ? '电影' : '' }}
              </van-tag>
              <van-tag
                plain
                type="primary"
                v-for="genres in item.genres"
                :key="genres"
              >
                {{ genres }}
              </van-tag>
            </div>
          </div>
          <!-- 想看按钮 -->
          <div class="like">
            <van-icon name="like-o" />
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
import { getTags } from '@/api/home'
export default {
  name: 'hot-movie',
  data () {
    return {
      info: [],
    }
  },
  methods: {},
  computed: {},
  components: {},
  created () {
    getTags()
      .then((res) => {
        // console.log(res)
        this.info = res.subjects
        // console.log(this.info)
      })
      .catch(console.log)
  },
}
</script>

<style lang='less' scoped>
.hot-movie {
  h1,h3 {
    margin: 0;
    padding: 0;
  }
  width: 100vw;
  .hot-movie-item > a {
    color: #000;
    width: 100vw;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 10px 0;
    padding: 0 5px;
    box-sizing: border-box;
    .order {
      font-size: 24px;
      font-weight: bolder;
      width: 50px;
      text-align: center;
    }
    .pic {
      width: 50px;
      /deep/ .van-image__img {
        border-radius: 5px;
      }
    }
    .info-content {
      flex: 1;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 10px;
      .info {
        height: 80px;
        display: flex;
        flex-flow: column;
        justify-content: space-evenly;
        .rate {
          display: flex;
          align-items: center;
          color: #ff9a03;
        }
        .tags {
          display: flex;
          align-items: center;
          * {
            margin: 0 2px;
          }
        }
      }
    }
  }
}
</style>
